<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
<#assign base=request.contextPath  />
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/frame/static/css/style.css">
    <link rel="icon" href="${base}/frame/static/image/code.png">
<script type="text/javascript" src="${base}/js/zhang.js"></script>
<script type="text/javascript" src="${base}/frame/layui/layui.all.js"></script>
    <script src="${base}/jquery-1.8.3.min.js"></script>
    <style type="text/css">
        html { overflow-x: hidden; overflow-y: auto; }
      </style>
</head>
</html>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>角色管理</legend>
</fieldset>
	<div class="demoTable"style="padding:10px;">

          <div class="layui-inline">
        	    <input class="layui-input" name="id" id="demoReload" style="height: 31px" autocomplete="off">
          </div>
        <button class="layui-btn layui-btn-sm layui-btn-normal" id="btn1" data-type="reload" style="background-color: #0092EF;">搜索</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" id="btn2" data-method="offset" type="button">添加角色</button>
    </div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<#--<script type="text/html" id="barDemo">-->
  <#--<i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="edit" href="javascript:void(0)"  onclick="delectRole('{{d.id}}')"  style="font-size: 20px;" ></i>-->
<#--</script>-->
<script type="text/html" id="barDemo">
    <betton  class="layui-btn layui-btn-danger layui-btn-xs " lay-event="edit"onclick="delectRole('{{d.id}}')"  >删除</betton>
</script>
<script src="${base}/js/layui/layui.js"></script>
<script>
layui.use(['form','layer','laydate','table'], function(){
  var form = layui.form
      ,$ = layui.jquery
      ,layer = layui.layer
      ,laydate = layui.laydate
      ,table = layui.table;
  table.render({
    elem: '#test'
     ,size: 'sm'//小尺寸的表格
    ,url:'${base}/ptRole/findRole'
    ,cols: [[
      //{field:'username',templet:function(val){return val.LAY_INDEX}, align: 'center',width:80, title: '序号'},
      {field:'roleName',align: 'center', title: '角色'}
//      ,{field:'createTime', align: 'center',templet:function(val){
//              return changeDateFormat(val.createTime)
//          }, title: '创建时间'}
      ,{field: 'eczxxxxema', title: '操作', align: 'center', toolbar: '#barDemo'}
    ]]
    ,id:'testReload'
      ,height:480
      ,page: {
          layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
          ,theme: '#9AC747'
          ,limit: 10
      }  ,done: function(res, curr, count){
          this.where={};
      }
  });
    $('#btn1').on('click', function(){
        var whereData={};
       whereData.roleName=Trim($("#demoReload").val())
        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/ptRole/findRole'
            ,where: whereData
        });

    });
  var active = {
    	offset: function(othis){
    	  var type = othis.data('type')
    	  ,text = othis.text();
		  layer.open({
		  type: 2,
		  title: '添加角色',

		  shadeClose:false ,
		  area:['560px','560px'],
		  content: '${base}/ptRole/Role_add',
		  success: function (layero, index) {
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
           }
		});
	}
  };
   $('#btn2').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });
});

function delectRole(id){

layer.confirm('真的要删除吗?', function(index){
 $.ajax({
    type:"POST",
       url:"${base}/ptRole/deleteRole",
       data:{"id":id},
           success : function(data){
                layer.msg(data)
           var table = layui.table;
            //表刷新方法
              table.reload('testReload', {
                   url: '${base}/ptRole/findRole'
                      ,where: {} //设定异步数据接口的额外参数
                                  });
                                    layer.close(index);
                       }
                 });

} );
            }
</script>
</script>
</body>
</html>